package zhihui.mobile.uitils;

import android.content.Context;
import android.text.TextUtils;

import com.zgm.utils.StringUtils;

import zhihui.mobile.R;
import zhihui.mobile.bean.phone.PhoneCode;

/**
 * Created by 张公铭 on 2017/7/13 0013.
 */

public class CheckUtils
{
    private static Context mContext;

    public static void initContext(Context context)
    {
        mContext = context;
    }

    public static String checkPhone(String phone)
    {
        if (TextUtils.isEmpty(phone))
        {
            return mContext.getString(R.string.phone_null);
        }
        if (phone.length() < 11 || !StringUtils.isNumeric(phone))
        {
            return mContext.getString(R.string.phone_error);
        }
        return "";
    }

    public static String checkPhoneCode(String code, PhoneCode curCode)
    {
        if (TextUtils.isEmpty(code))
        {
            return mContext.getString(R.string.code_null);
        }
        if (curCode == null)
        {
            return mContext.getString(R.string.code_end);
        }
        if (!curCode.getCode().equals(code))
        {
            return mContext.getString(R.string.code_error);
        }
        long time = System.currentTimeMillis();
        if (time > (curCode.getTime() + 1000 * 60 * 10))
        {
            return mContext.getString(R.string.code_end);
        }
        return "";
    }

    public static String checkPassword(String password)
    {
        if (TextUtils.isEmpty(password))
        {
            return mContext.getString(R.string.password_null);
        }
        if (password.length() < 6)
        {
            return mContext.getString(R.string.passwrod_error);
        }
        return "";
    }
}
